<?php
/**
 *  This file takes input from ajax and returns result.
 *  It looks for routes when user specified two points 
 */
include_once 'HatBulucu.php';

if (isset($_POST['data'])) {
	$res = json_decode(stripslashes($_POST['data']), true);
        
        //creating hatbulucu object with given input
        $hatBulucu = new HatBulucu($res);
        $result['tek'] = array();
        
        //looks for a single route that goes both points
        $result['tek'] = $hatBulucu->tekHatBul();
        
        //if it cant find any single route it creates a new array and populates it
        //with possible two routes
        if (count($result['tek']) == 0) {
            $result['iki'] = array();
            $result['iki'] = $hatBulucu->ikiHatBul();
        }
	header("Content-type: text/plain");
	
	echo json_encode($result);
}
